package demoTest;

public class StringDemo {

	public void change(String str) {
		str = "改变";
	}
	public static void main(String[] args) {
		String str1 = "哈哈";
		StringDemo ss = new StringDemo();
		ss.change(str1);
		System.out.println(str1);
		StringBuilder sb = new StringBuilder("abcde");
		System.out.println(sb.hashCode());
		sb.setCharAt(2, 'M');
		System.out.println(sb.hashCode());
		System.out.println(Integer.toHexString(sb.hashCode()));
		System.out.println(sb);

		System.out.println("=========================");
		//以下两者是等价的
		int i = 9;
		String str =  i + "";
		String str2 = String.valueOf(i);

//以下两者也是等价的
		String s = "abc" + str1;
		String s2 = new StringBuilder("abc").append(str1).toString();

		System.out.println("str===str2" + str == str2);
		System.out.println("s===s2" + s == s2);


		/**
		 * 编译期确定
		 * 对于final修饰的变量，它在编译时被解析为常量值的一个本地拷贝存储到自己的常量池中或嵌入到它的字节码流中。
		 * 所以此时的"a" + s1和"a" + "b"效果是一样的。故结果为true。
		 */
		String s0 = "ab";
		String s1 = "b";
		String s02 = "a" + "b";
		String s03 = new String("ab");
		System.out.println((s0 == s02)); //result = true
		System.out.println((s0 == s03)); //result = true


	}
}
